package com.sys.basics.utils;

import com.sys.basics.config.constant.SystemConstant;
import org.apache.shiro.crypto.SecureRandomNumberGenerator;
import org.apache.shiro.crypto.hash.SimpleHash;

import java.util.HashMap;


public class CryptoUtils {
    public static HashMap<String, String> saltEncrypt(String pwd) {
        //盐
        String salt = new SecureRandomNumberGenerator().nextBytes().toHex();
        //加密
        SimpleHash simpleHash = new SimpleHash(SystemConstant.ALGORITHM_NAME, pwd, salt, SystemConstant.HASH_ITERATIONS);
        String saltPassword = simpleHash.toString();

        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("salt", salt);
        hashMap.put("password", saltPassword);
        return hashMap;
    }
}
